﻿@{
    ViewBag.Title = "Admin menu manager";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

@model IEnumerable<RedSand.Site.Models.ActionInfo>
<script type="text/javascript">
    $(function () {
        $('#action-save').bind('click', function (event) {
            var data = ""
            $('.table-list tr:gt(0)').not('.nonebg').each(function () {
                data += "&RoleIDs=";
                $(this).find('input:checkbox:checked').each(function () {
                    data += "[" + $(this).val() + "]";
                });
            });
            $('#loading-panel').show();
            $.post("/action/save?" + data.substring(1), function () {
                $('#loading-panel').hide();
            });
            event.preventDefault();
        });

    });
           
</script>
<div class="panel">
    <div class="panel-header">
        <span>Admin menu manager</span>
    </div>
    <div class="panel-content">
        @if (ViewBag.RoleList == null)
        {
            <div class="message warning">You must create role first</div>
        }
        else
        {
            <table class="table-list">
                <thead>
                    <tr>
                        <th class="width-250">
                            Link
                        </th>
                        @foreach (var item in ViewBag.RoleList)
                        {
                            <th class="width-120">
                                @item.Name
                            </th>
                        }
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model)
                    {
                        if (item.ParentID == 0)
                        {
                            <tr class="nonebg" style="background: #dfdfdf">
                                <td colspan="@(ViewBag.RoleList.Count+1)" style="font-weight:bold">
                                    @item.Name
                                </td>
                            </tr>
                        }
                        else
                        {
                            <tr>
                                <td>
                                    @item.Name
                                </td>
                                @Html.Action("GetRoleCheckList", new { Link = item.Link })
                            </tr>
                        }
                    }
                </tbody>
            </table>
            <div class="panel-button-row">
                <a href="#" id="action-save" class="button">Save</a>
            </div>
        }
    </div>
</div>
